<template>
  <view class="movie-detail">
    <view class="movie-header">
      <image class="movie-backdrop" src="/static/logo.png" mode="aspectFill" />
      <view class="play-icon" @click="playHeaderVideo">▶</view>
      <view class="movie-info">
        <image class="movie-poster" src="/static/logo.png" mode="aspectFill" />
        <view class="movie-meta">
          <text class="movie-title">电影标题</text>
          <view class="movie-stats">
            <text class="movie-rating">9.0</text>
            <text class="movie-year">2024</text>
            <text class="movie-duration">120分钟</text>
          </view>
          <view class="movie-genres">
            <text class="genre-tag">动作</text>
            <text class="genre-tag">冒险</text>
          </view>
        </view>
      </view>
    </view>

    <view class="movie-section">
      <view class="section-title">剧情简介</view>
      <text class="movie-plot">这里是电影的剧情简介，详细描述电影的故事情节、背景设定等内容。</text>
    </view>

    <view class="movie-section">
      <view class="section-title">演职员表</view>
      <scroll-view class="cast-scroll" scroll-x>
        <view class="cast-item" v-for="i in 5" :key="i">
          <image class="cast-avatar" src="/static/logo.png" mode="aspectFill" />
          <text class="cast-name">演员名字</text>
          <text class="cast-role">角色名</text>
        </view>
      </scroll-view>
    </view>

    <view class="movie-section">
      <view class="section-title">用户评论</view>
      <view class="comment-list">
        <view class="comment-item" v-for="i in 3" :key="i">
          <view class="comment-header">
            <text class="comment-user">用户名</text>
            <text class="comment-rating">8.5</text>
          </view>
          <text class="comment-content">这是一条用户评论，分享了对电影的看法和感受。</text>
          <text class="comment-time">2024-03-01</text>
        </view>
      </view>
      <button class="comment-btn" type="primary">写评论</button>
    </view>

    <view class="movie-section">
      <view class="section-title">预告片</view>
      <view class="trailer-container">
        <video-player
          v-if="showPlayer"
          :src="trailerUrl"
          :poster="trailerPoster"
          :autoplay="true"
        />
        <template v-else>
          <image class="trailer-placeholder" :src="trailerPoster" mode="aspectFill" />
          <text class="play-icon" @click="playerClick">▶</text>
        </template>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import VideoPlayer from '../../components/VideoPlayer.vue';

// 头部视频跳转
const playHeaderVideo = () => {
  uni.navigateTo({
    url: '/pages/videoPlayer/index'
  });
}

// 预告片播放状态
const showPlayer = ref(false);
const trailerUrl = ref('https://media.w3.org/2010/05/sintel/trailer.mp4');
const trailerPoster = ref('/static/logo.png');

const playerClick = () => {
  showPlayer.value = true;
}
</script>

<style lang="scss">
.movie-detail {
  background-color: #f8f8f8;
  min-height: 100vh;
}

.movie-header {
  position: relative;
  height: 400rpx;
  
  .movie-backdrop {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0.7;
  }

  .header-video {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 1;
  }
  
  .play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 80rpx;
    color: #fff;
    background: rgba(0,0,0,0.5);
    width: 100rpx;
    height: 100rpx;
    border-radius: 50%;
    text-align: center;
    line-height: 100rpx;
    z-index: 2;
    cursor: pointer;
  }
  
  .movie-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    padding: 30rpx;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    
    .movie-poster {
      width: 200rpx;
      height: 280rpx;
      border-radius: 12rpx;
      margin-right: 20rpx;
    }
    
    .movie-meta {
      flex: 1;
      color: #fff;
      
      .movie-title {
        font-size: 36rpx;
        font-weight: bold;
        margin-bottom: 16rpx;
      }
      
      .movie-stats {
        display: flex;
        margin-bottom: 16rpx;
        
        .movie-rating, .movie-year, .movie-duration {
          margin-right: 20rpx;
          font-size: 24rpx;
        }
        
        .movie-rating {
          color: #ff9900;
        }
      }
      
      .movie-genres {
        display: flex;
        flex-wrap: wrap;
        
        .genre-tag {
          background: rgba(255,255,255,0.2);
          padding: 6rpx 16rpx;
          border-radius: 30rpx;
          font-size: 22rpx;
          margin-right: 12rpx;
          margin-bottom: 12rpx;
        }
      }
    }
  }
}

.movie-section {
  background: #fff;
  margin: 20rpx;
  padding: 30rpx;
  border-radius: 12rpx;
  
  .section-title {
    font-size: 32rpx;
    font-weight: bold;
    margin-bottom: 20rpx;
    color: #333;
  }
  
  .movie-plot {
    font-size: 28rpx;
    color: #666;
    line-height: 1.6;
  }
}

.cast-scroll {
  white-space: nowrap;
  
  .cast-item {
    display: inline-block;
    width: 160rpx;
    margin-right: 20rpx;
    text-align: center;
    
    .cast-avatar {
      width: 120rpx;
      height: 120rpx;
      border-radius: 60rpx;
      margin-bottom: 10rpx;
    }
    
    .cast-name {
      font-size: 26rpx;
      color: #333;
      display: block;
    }
    
    .cast-role {
      font-size: 22rpx;
      color: #999;
      display: block;
    }
  }
}

.comment-list {
  .comment-item {
    padding: 20rpx 0;
    border-bottom: 1px solid #eee;
    
    .comment-header {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10rpx;
      
      .comment-user {
        font-size: 28rpx;
        color: #333;
        font-weight: bold;
      }
      
      .comment-rating {
        font-size: 26rpx;
        color: #ff9900;
      }
    }
    
    .comment-content {
      font-size: 26rpx;
      color: #666;
      line-height: 1.5;
      margin-bottom: 10rpx;
    }
    
    .comment-time {
      font-size: 22rpx;
      color: #999;
    }
  }
}

.comment-btn {
  margin-top: 30rpx;
  width: 100%;
}

.trailer-container {
  position: relative;
  height: 400rpx;
  border-radius: 12rpx;
  overflow: hidden;
  
  .trailer-placeholder {
    width: 100%;
    height: 100%;
  }
  
  .play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 80rpx;
    color: #fff;
    background: rgba(0,0,0,0.5);
    width: 100rpx;
    height: 100rpx;
    border-radius: 50%;
    text-align: center;
    line-height: 100rpx;
  }
}
</style>